﻿//-----------------------------------------------------------------------
// <copyright file="IRepository.cs" company="WpfDevelopment.com">
//     Copyright WpfDevelopment.com. All rights reserved.
// </copyright>
//-----------------------------------------------------------------------
namespace WpfDevelopment.Data
{
    using System;
    using System.Diagnostics.CodeAnalysis;
    using System.Linq;
    using System.Linq.Expressions;
    using WpfDevelopment.MVVM;

    /// <summary>
    /// The interface of the global repository to persist objects
    /// </summary>
    public interface IRepository
    {
        /// <summary>
        /// Gets the unit of work.
        /// </summary>
        /// <value>The unit of work.</value>
        IUnitOfWork UnitOfWork { get; }

        /// <summary>
        /// Adds the specified entity.
        /// </summary>
        /// <typeparam name="T">The type of entity to add</typeparam>
        /// <param name="entity">The entity to add.</param>
        /// <returns>The added entity</returns>
        T Add<T>(T entity) where T : ModelBase;

        /// <summary>
        /// Updates the specified entity.
        /// </summary>
        /// <typeparam name="T">The type of entity to update</typeparam>
        /// <param name="entity">The entity to update.</param>
        /// <returns>The updated entity</returns>
        T Update<T>(T entity) where T : ModelBase;

        /// <summary>
        /// Deletes the specified entity.
        /// </summary>
        /// <typeparam name="T">The type of entity to delete</typeparam>
        /// <param name="entity">The entity.</param>
        void Delete<T>(T entity) where T : ModelBase;

        /// <summary>
        /// Gets this instance.
        /// </summary>
        /// <typeparam name="T">The type of entities to get</typeparam>
        /// <returns>An IQueryable of the type requested</returns>
        IQueryable<T> Query<T>() where T : ModelBase;

        /// <summary>
        /// Gets this instance.
        /// </summary>
        /// <typeparam name="T">The type of entities to get</typeparam>
        /// <param name="queryStatement">The query statement.</param>
        /// <returns>
        /// An IQueryable of the type requested
        /// </returns>
        [SuppressMessage("Microsoft.Design", "CA1006:DoNotNestGenericTypesInMemberSignatures", Justification = "Lambda")]
        IQueryable<T> Query<T>(Expression<Func<T, bool>> queryStatement) where T : ModelBase;

        /// <summary>
        /// Gets a single entity.
        /// </summary>
        /// <typeparam name="T">The type of entity to get</typeparam>
        /// <param name="primaryKey">The primary key.</param>
        /// <returns>The entity requested</returns>
        T GetEntity<T>(object primaryKey) where T : ModelBase;
    }
}
